#ifndef _COMPILATION_TASK_PHI_H_
#define _COMPILATION_TASK_PHI_H_

#include <compilation/Forward.h>

#include <set>

#include <compilation/instruction/Traits.h>

#include <compilation/Table.h>


namespace compilation
{

class PhiIsBefore
{
public:

  bool operator()(VirtualExpression* fst, VirtualExpression* snd) const;
};

class PhiLabelResult
{
public:

  typedef std::set<VirtualExpression*, PhiIsBefore>
  ModifiedVariables;

  typedef std::map<
  VirtualExpression*,
  std::pair<GotoInstruction*, GotoInstruction*>,
  PhiIsBefore>
  Map;

private:

  Map m_map;

  bool m_hasMark;

  Scope m_scope;

  ModifiedVariables m_variablesToAdd;

public:

  PhiLabelResult(void)
    : m_hasMark(false) {}

  void mark(void)
  { m_hasMark = true; }

  void setScope(const Scope& scope)
  { m_scope = scope; }

  Scope const& getScope(void) const
  { return m_scope; }

  LocalVariableExpression getAfterScopeLocalVariable() const;

  Map const& map(void) const
  { return m_map; }

  Map& map(void)
  { return m_map; }

  bool hasMark(void) const
  { return m_hasMark; }

  const ModifiedVariables& variablesToAdd(void) const
  { return m_variablesToAdd; }

  ModifiedVariables& variablesToAdd(void)
  { return m_variablesToAdd; }

  typedef Map::iterator iterator;
  typedef Map::const_iterator const_iterator;
};

} // compilation

#endif // _COMPILATION_TASK_PHI_H_
